from django.shortcuts import render,redirect
from django.views import View
# Create your views here.

from .models import *
class Add(View):
    def get(self,request):
        return render(request, 'add.html')

    def post(self, request):
        username = request.POST.get('username')
        password = request.POST.get('password')
        img = request.FILES.get('img')
        type = request.POST.get('type')
        user =User.objects.create(
            username=username,
            password=password,
            img=img,
            type=type
        )
        message = '添加成功'
        return render(request, 'add.html', locals())

class show_add(View):
    def get(self,request):
        show_list = User.objects.all()
        return render(request, 'show_add.html', locals())

class Delete(View):
    def get(self,request):
        id =request.GET.get('id')
        User.objects.filter(pk=id).delete()
        return redirect('/show/')
